<?php

namespace app\hospital\controller;
use app\BaseController;
use app\hospital\model\manageruser;
use think\facade\Request;
use think\facade\Session;
use think\facade\View;

class admin extends BaseController
{
    function login()
    {
        $m=Request::method();
        if($m=="GET"){
            return View::fetch();
        }else{
            $u=Request::param('user');
            $p=Request::param('pwd');
            $id=Request::param('id');
            $user=manageruser::where(['name'=>$u,'pwd'=>$p,'id'=>$id])->find();
            if($user){
                Session::set('admin',$user['name']);
                Session::set('id',$user['id']);
                Session::set('pwd',$user['password']);
                return '登录成功';
            }else{
                return '用户名或密码有误，登录不成功';
            }
        }
    }
    function logout()
    {
        Session::delete('admin');
        Session::delete('id');
        Session::delete('pwd');
        return redirect('/index.php/hospital/index');
    }
}